package com.first.group.newhouse.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.first.group.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.first.group.newhouse.entity.NewHouseEntity;
import com.first.group.newhouse.service.NewHouseService;
import com.first.group.common.utils.R;


/**
 * 这是新房信息表
 *
 * @author zy
 * @email 2067065884@qq.com
 * @date 2021-10-14 19:04:42
 */
@RestController
@RequestMapping("newhouse/newhouse")
public class NewHouseController {
    @Autowired
    private NewHouseService newHouseService;


    @GetMapping("/updateStatus")
    public R updateStatus(@RequestParam("newHouseId") Long newHouseId) {
        return newHouseService.updateStatus(newHouseId);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, Model model) {

        PageUtils page = newHouseService.queryPage(params);
        return R.ok().put("page",page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{newHouseId}")
    public R info(@PathVariable("newHouseId") Long newHouseId) {
        NewHouseEntity newHouse = newHouseService.getById(newHouseId);

        return R.ok().put("newHouse", newHouse);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody NewHouseEntity newHouse) {

        return newHouseService.saveNewHouse(newHouse);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody NewHouseEntity newHouse) {
        newHouseService.updateById(newHouse);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] newHouseIds) {
        newHouseService.removeByIds(Arrays.asList(newHouseIds));

        return R.ok();
    }

}
